package com.jb.repair.acticity;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jb.repair.F1Application;
import com.jb.repair.R;
import com.jb.repair.adapter.TaskTableAdapter;
import com.jb.repair.common.AppConfig;
import com.jb.repair.common.Constants;
import com.jb.repair.dao.DBHelper;
import com.jb.repair.dao.LocalDbDao;
import com.jb.repair.model.RegularWorkListJson;
import com.jb.repair.model.RegularWorkModel;
import com.jb.repair.model.TaskTableModel;
import com.jb.repair.model.User4Json;
import com.jb.repair.net.HttpClient;
import com.jb.repair.net.HttpCookies;
import com.jb.repair.util.IntentUtils;
import com.jb.repair.util.MD5Util;
import com.jb.repair.util.MessageUtil;
import com.jb.repair.view.ItemTitleView;
import com.jb.repair.view.TitleView;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TaskDetailActivity extends BaseActivity {

    /* 数据相关变量 */
    private RegularWorkModel regularWorkModel = null;
    private List<TaskTableModel> taskTableModelList = new ArrayList<TaskTableModel>();
    LocalDbDao localDbDao = null;
    private Gson gson = new Gson();
    private int taskTableNum = 0;
    private int accessNetCount = 0;
    private TaskTableModel model = null;//当前操作的任务表对象
    private int index = -1;//当前操作的任务表在taskTableModelList中的序号

    /* view类变量 */
    private TitleView titleView;
    private TextView tvTaskName, tvTaskContent, tvProfess, tvFinishTime, tvPersonName, tvStatus;
    private TaskTableAdapter taskTableAdapter;
    private ItemTitleView itvTaskTable;
    private RelativeLayout rlDelayIntro, rlCancelIntro;
    private TextView tvDelayDate, tvDelayResult, tvCancelDate, tvCancelResult;
    private LinearLayout rlModelListHeader;
    private ListView lvModelList;

    /* 其他变量 */
    private Handler handler;

    /*常量*/
    public static final int MSG_TYPE_DOWNLOAD = 0;
    public static final int MSG_TYPE_REGISTER = 1;
    public static final int MSG_TYPE_UPLOAD = 2;

    private static final String TAG = "TaskDetailActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initVariables();
        initViews();
        initListeners();
        initData();

    }

    private void initVariables() {
        regularWorkModel = (RegularWorkModel) getIntent().getSerializableExtra("task_detail");
        Log.i(TAG, "任务详情为：" + regularWorkModel.toString());
        localDbDao = LocalDbDao.getInstance(this);
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case MSG_TYPE_DOWNLOAD://下载任务表
                        Log.i(TAG, "准备下载任务表");
                        model = (TaskTableModel) msg.obj;
                        index = msg.arg1;
                        MessageUtil.showProgressDialog(TaskDetailActivity.this, "正在下载模板");
                        new DownFile().execute(AppConfig.BASE_URL + Constants.GET_TASK_TABLE_URL + "?guid=" + model.MBFJID, AppConfig.REGULAR_WORK_MODEL_DIR_PATH, model.GUID + ".xlsx", index + "");
                        break;
                    case MSG_TYPE_REGISTER:
                        Log.i(TAG, "准备打开任务表");
                        String filePath = msg.obj.toString();
                        Log.i(TAG, "文件路径为：" + filePath);
                        IntentUtils.JumpToIntent(TaskDetailActivity.this, "xlsx", filePath);
                        break;
                    case MSG_TYPE_UPLOAD:
                        Log.i(TAG, "准备上传任务表");
                        model = (TaskTableModel) msg.obj;
                        index = msg.arg1;
                        Log.i(TAG, "index = " + index);
                        //比较文件的最后修改时间和更新时间
                        String path = AppConfig.REGULAR_WORK_MODEL_DIR_PATH + taskTableModelList.get(index).GUID + ".xlsx";
                        File file = new File(path);
                        if (file.exists()) {
                            //获取文件最后修改时间
                            Long lastModifyTime = file.lastModified();
                            Log.i(TAG, "该文件上次修改时间为：" + lastModifyTime);
                            try {
                                Long lastUploadTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(taskTableModelList.get(index).UPLOAD_TIME).getTime();

                                Log.i(TAG, "该文件上次上传时间为：" + lastUploadTime);
                                if (lastModifyTime > lastUploadTime) {
                                    //上传该任务表
                                    MessageUtil.showProgressDialog(TaskDetailActivity.this, "正在上传任务表");
                                    new UploadFile().execute(AppConfig.BASE_URL + Constants.UPLOAD_TASK_TABLE_URL, AppConfig.REGULAR_WORK_MODEL_DIR_PATH + model.GUID + ".xlsx", model.GUID + ".xlsx", index + "");
                                }
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }

                        } else {
                            Log.i(TAG, "文件不存在");

                        }
                        break;
                }
            }
        };
    }

    private void initViews() {
        setContentView(R.layout.activity_task_detail);
        titleView = (TitleView) findViewById(R.id.tiv_title);
        lvModelList = (ListView) findViewById(R.id.lv_model_list);
        rlModelListHeader = (LinearLayout) getLayoutInflater().inflate(R.layout.layout_model_list_header, null);

        tvTaskName = (TextView) rlModelListHeader.findViewById(R.id.tv_task_name);
        tvTaskContent = (TextView) rlModelListHeader.findViewById(R.id.tv_task_content);
        tvProfess = (TextView) rlModelListHeader.findViewById(R.id.tv_task_pro);
        tvFinishTime = (TextView) rlModelListHeader.findViewById(R.id.tv_finish_time);
        tvPersonName = (TextView) rlModelListHeader.findViewById(R.id.tv_person_name);
        tvStatus = (TextView) rlModelListHeader.findViewById(R.id.tv_status);
        rlDelayIntro = (RelativeLayout) rlModelListHeader.findViewById(R.id.rl_delay_intro);
        rlCancelIntro = (RelativeLayout) rlModelListHeader.findViewById(R.id.rl_cancel_intro);
        tvDelayDate = (TextView) rlModelListHeader.findViewById(R.id.tv_delay_date);
        tvDelayResult = (TextView) rlModelListHeader.findViewById(R.id.tv_delay_result);
        tvCancelDate = (TextView) rlModelListHeader.findViewById(R.id.tv_cancel_date);
        tvCancelResult = (TextView) rlModelListHeader.findViewById(R.id.tv_cancel_result);

        itvTaskTable = (ItemTitleView) rlModelListHeader.findViewById(R.id.itv_model_list);

        lvModelList.addHeaderView(rlModelListHeader);

    }

    private void initListeners() {
        //点击关闭该页面
        titleView.setOnClickListener(new TitleView.OnTitleViewClickListener() {
            @Override
            public void onLeftTextClick(View view) {
                super.onLeftTextClick(view);
                TaskDetailActivity.this.finish();
            }

            @Override
            public void onLeftImageClick(View view) {
                super.onLeftImageClick(view);
                TaskDetailActivity.this.finish();
            }
        });
    }

    private void initData() {
        /* 初始化任务详情 */
        tvTaskName.setText(regularWorkModel.TASK_NAME);
        tvTaskContent.setText(regularWorkModel.GZNR);
        tvProfess.setText("未知专业");
        tvFinishTime.setText(regularWorkModel.SHOULD_FINISH_TIME);
        tvPersonName.setText(F1Application.getUserName() == null ? "未知" : F1Application.getUserName());
        try {
            tvStatus.setText(new JSONObject(Constants.CT_TASK_STATUS).getString(regularWorkModel.TASK_STATUS.trim()));
            tvStatus.setTextColor(getResources().getColor(regularWorkModel.TASK_STATUS.equals("0700202") ? R.color.green_dark : R.color.red));
        } catch (Exception e) {
            tvStatus.setText("未知状态");
        }
        if (regularWorkModel.TASK_STATUS.equals("0700205")) {
            //已延期
            rlDelayIntro.setVisibility(View.VISIBLE);
            tvDelayDate.setText(regularWorkModel.DELAY_TIME);
            tvDelayResult.setText(regularWorkModel.DELAY_RESULT);
        }
        if (regularWorkModel.TASK_STATUS.equals("0700206")) {
            //已取消
            rlCancelIntro.setVisibility(View.VISIBLE);
            tvCancelDate.setText(regularWorkModel.update_time);
            tvCancelResult.setText(regularWorkModel.cancel_result);
        }

        /* 初始化任务表列表 */

        showTaskModelList();
    }


    /**
     * 显示任务表列表
     */
    private void showTaskModelList() {
        // 检查该任务对应的模板信息是否已经存在数据库里
        taskTableModelList = localDbDao.getTaskTableListById(regularWorkModel.GUID);
//        Log.i(TAG, "任务表为：" + taskTableModelList.toString());
        taskTableNum = taskTableModelList.size();
        if (taskTableNum == 0) {
            //说明没有下载过模板信息，向服务器请求
            Log.i(TAG, "没有下载过任务表信息，向服务器请求");

            if (accessNetCount++ < 1) {
                MessageUtil.showProgressDialog(TaskDetailActivity.this, "正在请求任务表");
                new getTaskTableListTask().execute();
            }
        }
            Log.i(TAG, "taskTableNum = " + taskTableNum);
            itvTaskTable.setTvRightText("共 " + taskTableNum + " 个");
        taskTableAdapter = new TaskTableAdapter(TaskDetailActivity.this, taskTableModelList, handler, regularWorkModel.TASK_STATUS);
            lvModelList.setAdapter(taskTableAdapter);
            taskTableAdapter.notifyDataSetChanged();

    }

    @Override
    public void onBackPressed() {
        this.finish();
    }


    private class getTaskTableListTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {

            String url = Constants.GET_TASK_TABLE_LIST_URL.contains("http") ? Constants.GET_TASK_TABLE_LIST_URL : AppConfig.BASE_URL + Constants.GET_TASK_TABLE_LIST_URL;
            Log.i(TAG, "请求任务表列表工作URL：" + url);
            Map<String, String> map = new HashMap<>();
            map.put("service", "dqgz_dqgzrwdetailgridservice");
            JSONObject filterStr = new JSONObject();
            try {
                JSONObject object = new JSONObject();
                object.put("target", "taskId");
                object.put("type", "=");
                object.put("value", regularWorkModel.GUID);
                JSONArray filterMap = new JSONArray();
                filterMap.put(object);
                filterStr.put("filterMap", filterMap);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            map.put("filterStr", filterStr.toString());
            map.put("start", "0");
            map.put("limit", "0");
            Log.i(TAG, "参数为：" + map.toString());
            String result = new HttpClient(TaskDetailActivity.this).doGet(url, map);
            Log.i(TAG, "请求任务表列表返回結果：" + result);
            return result;
        }

        @Override
        protected void onPostExecute(String s) {
            MessageUtil.dismissProgressDialog();
            super.onPostExecute(s);
            JSONObject resultJson = null;
            try {
                resultJson = new JSONObject(s);
            } catch (JSONException e) {
                e.printStackTrace();
                try {
                    resultJson = new JSONObject(s);
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
                if (s.contains("601")) {
                    //说明没有登录
                    Log.i(TAG, "执行登录操作");
                    new LoginTask().execute(Constants.LOGIN_NAME_FRO_REGULAR, MD5Util.parse(Constants.LOGIN_PSW_FRO_REGULAR), "0");
                    return;
                }
            }
            try {
                if (resultJson != null) {
                    if (resultJson.has("total") && resultJson.getInt("total") > 0) {
                        //返回成功
                        if (resultJson.has("rows")) {
                            Log.i(TAG, "开始解析rows...");
                            taskTableModelList = gson.fromJson(resultJson.getJSONArray("rows").toString(), new TypeToken<List<TaskTableModel>>() {
                            }.getType());

                            Log.i(TAG, "taskList解析成功" + taskTableModelList.toString());
                            MessageUtil.showToast(TaskDetailActivity.this, "数据获取成功");

                        }
                    } else {
                        MessageUtil.showToast(TaskDetailActivity.this, "任务表获取失败");
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
                Log.e(TAG, "解析json数据时发生异常");
                taskTableModelList = null;
            }
            if (taskTableModelList != null) {
                //存储到数据库中
                saveTaskTableToDb(taskTableModelList);

                //显示到界面中
                showTaskModelList();

            }
        }
    }


    private void saveTaskTableToDb(List<TaskTableModel> list) {
        if (localDbDao != null)
            localDbDao.insertIntoCtTaskModel(list);
        else
            Log.e(TAG, "localDbDao = null");
    }


    /**
     * 模拟登录用以获取cookie
     * 第一个参数 登录名
     * 第二个参数 密码（MD5）
     * 第三个参数 回调操作 0-获取getTaskTableListTask 1-下载文件 2-上传文件
     */
    private class LoginTask extends AsyncTask<String, Void, String> {
        private String callback = "";

        @Override
        protected String doInBackground(String... params) {
            callback = params[2];
            String url = Constants.LOGIN_URL_FRO_REGULAR.contains("http") ? Constants.LOGIN_URL_FRO_REGULAR : AppConfig.BASE_URL + Constants.LOGIN_URL_FRO_REGULAR;
            Log.i(TAG, "登陆url：" + url);
            String result = "";
            Map<String, String> map = new HashMap<>();
            map.put("username", params[0]);
            map.put("password", params[1]);
            map.put("pageStyle", "");
            map.put("logined", params[0]);
            map.put("agent", "0");
            result = new HttpClient(TaskDetailActivity.this).doPost(url, map);
            Log.i(TAG, "登陆返回结果：" + result);
            return result;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            Gson gson = new Gson();
            try {
                User4Json uj = gson.fromJson(s, new TypeToken<User4Json>() {
                }.getType());
                if (uj.successful.equals("true")) {
                    MessageUtil.showToast(TaskDetailActivity.this, "验证成功");
                    F1Application.setUserName(uj.resultValue.persName);
                    F1Application.setUserId(uj.resultValue.persGuid);
                    //执行回调
                    MessageUtil.showProgressDialog(TaskDetailActivity.this, "正在重新请求");
                    if (callback.equals("0")) {
                        new getTaskTableListTask().execute();
                    } else if (callback.equals("1")) {
                        new DownFile().execute(AppConfig.BASE_URL + Constants.GET_TASK_TABLE_URL + "?guid=" + model.MBID, AppConfig.REGULAR_WORK_MODEL_DIR_PATH, model.GUID + ".xlsx", index + "");
                    } else if (callback.equals("2")) {
                        new UploadFile().execute(AppConfig.BASE_URL + Constants.UPLOAD_TASK_TABLE_URL, AppConfig.REGULAR_WORK_MODEL_DIR_PATH + model.GUID + ".xlsx", model.GUID + ".xlsx", index + "");
                    }

                } else {
                    MessageUtil.showToast(TaskDetailActivity.this, uj.resultHint);
                    HttpCookies.setSessionId(null);
                }
            } catch (Exception e) {
                MessageUtil.showToast(TaskDetailActivity.this, "验证失败");
            }


        }
    }

    /**
     * 下载文件
     * 参数1：文件下载地址
     * 参数2：文件存储目录
     * 参数3：保存文件名
     * 参数4：在taskTableList中的序号
     */
    private class DownFile extends AsyncTask<String, String, Integer> {

        @Override
        protected Integer doInBackground(String... params) {
            try {
                String url = params[0];
                Log.i(TAG, "下载文件地址为: " + url);
                DefaultHttpClient client = new DefaultHttpClient();
                HttpGet httpRequest = new HttpGet(url);
                HttpCookies li = new HttpCookies(getApplicationContext());
                CookieStore cs = li.getuCookie();
                if (cs != null) {
                    client.setCookieStore(li.getuCookie());
                }
                HttpResponse httpResponse = client.execute(httpRequest);
                int resCode = httpResponse.getStatusLine().getStatusCode();
                Log.i(TAG, "resCode = " + resCode);
                if (resCode == 200) {
                    HttpEntity entity = httpResponse.getEntity();
                    int length = 0;
                    InputStream in = entity.getContent();
                    String path = params[1];
                    Log.i(TAG, "文件保存目录为：" + path);
                    File dir = new File(path);
                    if (!dir.exists()) {
                        dir.mkdirs();
                    }
                    File file = new File(path + params[2]);
                    FileOutputStream out = new FileOutputStream(file);
                    byte[] buff = new byte[1024 * 1024];
                    while ((length = in.read(buff)) > 0) {
                        out.write(buff, 0, length);
                    }
                    in.close();
                    out.flush();
                    out.close();
                    Log.i(TAG, "文件下载成功");
                    return Integer.parseInt(params[3]);
                } else if (resCode == 601) {
                    //未登录
                    return -2;
                } else {
                    Log.i(TAG, "文件下载失败");
                    return -1;
                }

            } catch (MalformedURLException e) {
                e.printStackTrace();
                return -1;
            } catch (IOException e) {
                e.printStackTrace();
                return -1;
            } catch (Exception e) {
                e.printStackTrace();
                return -1;
            }

        }


        @Override
        protected void onPostExecute(Integer integer) {
            MessageUtil.dismissProgressDialog();
            Log.i(TAG, "integer = " + integer);
            if (integer >= 0) {
                MessageUtil.showToast(TaskDetailActivity.this, "任务表下载成功");
                super.onPostExecute(integer);
                //修改taskTableModelList状态
                taskTableModelList.get(integer).STATUS = "1";//未上传
                taskTableAdapter.notifyDataSetChanged();
                //更新到数据库
                localDbDao.update(DBHelper.CT_TASK_MODEL_NAME, "STATUS", "1", taskTableModelList.get(integer).GUID);
            } else if (integer == -2) {
                //登录授权
                Log.i(TAG, "执行登录授权");
                new LoginTask().execute(Constants.LOGIN_NAME_FRO_REGULAR, MD5Util.parse(Constants.LOGIN_PSW_FRO_REGULAR), "1");
            } else {
                MessageUtil.showToast(TaskDetailActivity.this, "任务表下载失败");
            }

        }
    }

    /**
     * 上传任务表
     * param1:上传文件接口地址
     * param2:待上传文件路径
     * param3:待上传文件名称
     */
    private class UploadFile extends AsyncTask<String, String, String> {

        private int index;

        @Override
        protected String doInBackground(String... params) {
            Log.i(TAG, "文件上传接口地址为：" + params[0]);
            Log.i(TAG, "待上传文件路径为：" + params[1]);
            Log.i(TAG, "文件名称为：" + params[2]);
            Log.i(TAG, "index为：" + params[3]);
            index = Integer.parseInt(params[3]);
            String result = new HttpClient(getApplicationContext()).uploadTaskTable(params[0], params[1], params[2]);//0-成功 -1-失败 -2-未登录授权
            Log.i(TAG, "文件上传结果为：" + result);
            return result;
        }

        @Override
        protected void onPostExecute(String result) {
            MessageUtil.dismissProgressDialog();
            super.onPostExecute(result);
            try {
                JSONObject jsonObject = new JSONObject(result);
                if (jsonObject.has("success") && jsonObject.getBoolean("success")) {
                    JSONObject msgJsonObject = jsonObject.getJSONObject("msg");
                    Log.i(TAG, "msg = " + msgJsonObject.toString());
                    //把其中的objId保存下来，更新到任务模板详情中
                    String fjid = msgJsonObject.getString("objId");
                    Log.i(TAG, "objId = " + fjid);
                    taskTableModelList.get(index).FJID = fjid;
                    localDbDao.update(DBHelper.CT_TASK_MODEL_NAME, "FJID", fjid, taskTableModelList.get(index).GUID);//保存到数据库中
                    //调用提交报告接口
                    MessageUtil.showProgressDialog(TaskDetailActivity.this, "正在提交报告");
                    new SubmitReport().execute(AppConfig.BASE_URL + Constants.SUBMIT_REPORT_URL);
                }

            } catch (JSONException e) {
                e.printStackTrace();
                int resultCode = Integer.parseInt(result);
                if (resultCode == -2) {
                    //登录授权
                    Log.i(TAG, "执行登录授权");
                    new LoginTask().execute(Constants.LOGIN_NAME_FRO_REGULAR, MD5Util.parse(Constants.LOGIN_PSW_FRO_REGULAR), "2");
                } else if (resultCode == -3) {
                    //表示遇到未知错误，暂时用于后续流程调试 todo 记得删掉
                    //修改taskTableModelList状态
                    taskTableModelList.get(index).STATUS = "2";//已上传
                    taskTableAdapter.notifyDataSetChanged();
                    //更新到数据库
                    localDbDao.update(DBHelper.CT_TASK_MODEL_NAME, "STATUS", "2", taskTableModelList.get(index).GUID);
                } else {
                    MessageUtil.showToast(TaskDetailActivity.this, "任务表上传失败");
                }
            }
        }
    }

    /**
     * 提交报告
     * param1:提交报告接口地址
     */
    private class SubmitReport extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... params) {
            Log.i(TAG, "提交报告接口地址为：" + params[0]);
            Log.i(TAG, "当前操作序号为：" + index);
            model = taskTableModelList.get(index);
            Map<String, String> map = new HashMap<>();
            map.put("guid", model.FJID);
            map.put("taskId", model.TASK_ID);
            map.put("planId", model.PLAN_ID);
            map.put("mbid", model.MBID);
            map.put("sbId", model.EQ_ID);
            map.put("taskDetailGuid", model.GUID);
            Log.i(TAG, "参数为：" + map.toString());
            String result = new HttpClient(TaskDetailActivity.this).doPost(params[0], map);
            Log.i(TAG, "提交报告结果为：" + result);
            return result;
        }

        @Override
        protected void onPostExecute(String result) {
            MessageUtil.dismissProgressDialog();
            super.onPostExecute(result);
            try {
                JSONObject jsonObject = new JSONObject(result);
                if (jsonObject.has("success") && jsonObject.getBoolean("success")) {
                    //提交成功
                    MessageUtil.showToast(TaskDetailActivity.this, "上传成功");
                    //修改taskTableModelList状态
                    taskTableModelList.get(index).STATUS = "2";//已上传
                    //更新到数据库
                    localDbDao.update(DBHelper.CT_TASK_MODEL_NAME, "STATUS", "2", taskTableModelList.get(index).GUID);
                    String date = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()).toString();
                    Log.i(TAG, "上传时间为：" + date);
                    taskTableModelList.get(index).UPLOAD_TIME = date;
                    localDbDao.update(DBHelper.CT_TASK_MODEL_NAME, "UPLOAD_TIME", date, taskTableModelList.get(index).GUID);
                    taskTableAdapter.notifyDataSetChanged();
                    //更新该任务的状态为“未完成”
                    regularWorkModel.update_time = date;
                    regularWorkModel.TASK_STATUS = "0700207";
                    localDbDao.updateRegularWork(0, regularWorkModel);
                } else {
                    if (jsonObject.has("success") && !jsonObject.getBoolean("success") && jsonObject.has("message"))
                        MessageUtil.showToast(TaskDetailActivity.this, jsonObject.getString("message"));
                    else
                        MessageUtil.showToast(TaskDetailActivity.this, "上传失败");
                }


            } catch (JSONException e) {
                e.printStackTrace();
                MessageUtil.showToast(TaskDetailActivity.this, "上传失败");
            }
        }
    }


}
